package com.seal.commons.config.apollo.autoConfigure;

import com.seal.commons.config.apollo.configuration.ApolloProperties;
import com.seal.commons.config.apollo.locator.ApolloPropertySourceExtractor;
import com.seal.commons.config.apollo.refresh.ApolloConfigRefreshHistory;
import com.seal.commons.config.apollo.refresh.ApolloContextRefresher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@EnableConfigurationProperties(ApolloProperties.class)
public class ApolloConfigAutoConfiguration {

    @Autowired
    private ApolloProperties apolloProperties;

    @Bean
    public ApolloContextRefresher apolloContextRefresher(ApolloConfigRefreshHistory apolloConfigRefreshHistory) {
        return new ApolloContextRefresher(apolloProperties, apolloConfigRefreshHistory);
    }

    @Bean
    public ApolloConfigRefreshHistory apolloConfigRefreshHistory() {
        return new ApolloConfigRefreshHistory();
    }

    @Bean
    public ApolloPropertySourceExtractor apolloPropertySourceExtractor() {
        return new ApolloPropertySourceExtractor();
    }

}
